package com.ai.service.made.impl;

import com.ai.entity.alarm.SignalRecord;
import com.ai.mapper.alarm.SignalRecordMapper;
import com.ai.service.made.ISignalRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiaok
 * @since 2023-07-05
 */
@Service
public class SignalRecordServiceImpl extends ServiceImpl<SignalRecordMapper, SignalRecord> implements ISignalRecordService {

    @Override
    public SignalRecord getLastSingnalRecord(Integer funType) {

        SignalRecord signalRecord = this.getOne(new QueryWrapper<SignalRecord>()
                .eq("fun_type", funType)
                .orderByDesc("begin_time")
                .last("limit 1"));
        return signalRecord;
    }

    @Override
    public SignalRecord getLastSingnalRecord(Integer funType, String planNo, Integer doorNum) {

        SignalRecord signalRecord = this.getOne(new QueryWrapper<SignalRecord>()
                .eq("fun_type", funType)
                .eq(StringUtils.isNotBlank(planNo),"plan_no",planNo)
                .eq(null != doorNum,"door_num",doorNum)
                //且不等于空
//                .isNull("end_time")
                .isNotNull("begin_time")
                .orderByDesc(Collections.singletonList("begin_time"))
                .last("limit 1"));

        return signalRecord;
    }
}
